<template>
  <div class="container">
    <el-row class="">
      <el-col :span="16" align="left">
        <el-input v-model="data.params.expertName" placeholder="专家姓名" style="width: 150px; margin-right: 15px" clearable></el-input>
        <SelectOption :options="data.orgAllList" placeholder="专家类别" @change-value="changeValue1" > </SelectOption>
        <el-button color="#626aef" @click="search()">筛选</el-button>
      </el-col>
    </el-row>
    <div>
        <Table class="table_" :initSelection="data.initSelection" :operate="true" :tableArr="data.allTableData" :pagination="data.page" :columns="data.columns" @delectTable="delectIds"
        :total="data.page.total">
        </Table>
<!--        <div class="example-pagination-block">
              <el-pagination
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                :page-sizes="[10, 20, 30, 40,50,100]"
                background
                layout="prev, pager, next ,total,sizes,jumper"
                :total="data.page.total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"/>
        </div>-->
            <div class="example-pagination-block">
              <el-pagination
                :current-page="data.params.current"
                :page-size="data.params.size"
                :page-sizes="[10, 20, 30, 40,50,100]"
                background
                layout="prev, pager, next ,total,sizes,jumper"
                :total="data.page.total"
                @currentChange="(current) => {
               data.params.current = current;
               tableList();
             }"
                @sizeChange="(size) => {
               data.params.size = size;
               tableList();
             }"/>
        </div>
      </div>
  </div>
</template>

<script>
import { getSetUpExpertReview } from '@/views/science/api/digit'
import SelectOption from '@/views/science/components/selectOption/index.vue'
import Table from '@/views/science/components/table/table2.vue'
import { onMounted, reactive, ref, } from 'vue'
import tableData from '../tableHeader.json'
import { getDictionaryList, } from '@/views/science/api/common';

export default {
  components: {
    Table,
    SelectOption,
  },
  props: {
    initSelection:{
      type: Array,
      default:[]
    }
  },
  setup(props,{emit}) {
    console.log(props.initSelection,'props.initSelection  setUpExpertsDialog');
    const activeName = ref('first')
    const data = reactive({
      initSelection:[],
      allTableData:[],
      ids:[],
      columns: tableData.getSetUpExpertReview,
      page: { page: 1, limit: 10, total: 0 },
      orgAllList:[],//{itemText:'内部专家',itemValue:1},{itemText:'外部专家',itemValue:2}
      params: {
        expertName: "",
        expertType:'',
        current: 1,
        size: 10,
      },
    })
     //分页器信息
    const pagination = reactive({
      pageSize:10,
      currentPage:1,
    })
    //分页操作
    const handleSizeChange = (val) =>{
      data.params.size = val
      tableList()
    }
    const handleCurrentChange = (val) =>{
      data.params.current = val
      tableList()
    }
    //搜索
    const search = () =>{
      tableList();
    }
    //多选
    const delectIds = (ids) => {
      let ele = []
      // console.log('data.allTableData ',data.allTableData,ids);
           for (let i = 0; i < data.allTableData.length; i++) {
            for (let y = 0; y < ids.length; y++) {
            if(ids[y] === data.allTableData[i].id){
              ele.push({
                expertId:data.allTableData[i].employeeId,
                expertName:data.allTableData[i].expertName,
                positionName:data.allTableData[i].positionName,//职务
                expertiseArea:data.allTableData[i].reportExpertiseArea,//专业类型
                expertGrade:data.allTableData[i].expertGrade,//专业类型
                applicationId:'',
              })
            }
        }
      }
      emit('delectIdsSetUp', ele)
      // console.log('ids',ele);
    }
    // 分页

    let currentChange = (current) => {

      data.pagination.page = current;

      tableList();

    };
    //列表
    const tableList = async () => {
      let res = await getSetUpExpertReview(data.params)
      if (res.data.success) {
        console.log('设置专家',res.data.data.records);
        let records = res.data.data
        res.data.data.records.forEach(e => {
          e.expertType == 1 ? e.expertType = '内部专家' : e.expertType == 2 ? e.expertType ='外部专家' : e.expertType = ''
        });
        data.allTableData = res.data.data.records
        data.initSelection = data.allTableData.filter(item =>{
          return props.initSelection.includes(item.employeeId)
        });
        console.log( data.initSelection ,' data.initSelection ');
        data.page.total = records.total
      }
    }
    //选择专家类别
    const changeValue1 = (val) => {
      data.params.expertType = val.itemValue
      // tableList();
    }
    const getDictionaryList1 = async () => {
      const rst = await getDictionaryList(["ZYRC_ZLX"])
      data.orgAllList = rst.data.data.ZYRC_ZLX
    }
    onMounted(() => {
      tableList();
      getDictionaryList1()
    });

    return{
      activeName,
      pagination,
      data,
      search,
      delectIds,
      handleSizeChange,
      handleCurrentChange,
      changeValue1,
      tableList,
      currentChange,
    }
  },
}
</script>

<style lang="scss">
.table_{
  .el-pagination {
      display: none;
    }
}
</style>
<style lang="scss" scoped>
.example-pagination-block {
  margin-top: 15px;
  text-align: center;
}

:deep(.el-pagination .btn-next .el-icon) {
  margin: 0 auto;
}

:deep(.el-pagination .btn-prev .el-icon) {
  margin: 0 auto;
}
.container {
  background-color: white;
  padding: 20px;
}
</style>
